<?php

class User_profile extends DataMapper {
	
	var $table	= 'profiles';
    
    var $has_one = array(
			'user' => array(			
	            'class' => 'user',
	            'other_field' => 'user_profile',
	            'join_self_as' => 'profile',
	            'join_other_as' => 'user',
	            'join_table' => 'r_profiles_users'),
    		'country' => array(			
	            'class' => 'country',
	            'other_field' => 'user_profile',
	            'join_self_as' => 'profile',
	            'join_other_as' => 'country',
	            'join_table' => 'r_countries_profiles'),
    );
    
    var $validation = array(
    	'first_name' => array(
            'label' => 'First name',
            'rules' => array('always_run', 'trim', 'alpha_space', 'min_length' => 2, 'max_length' => 45),
		),
		'middle_name' => array(
            'label' => 'Middle name',
            'rules' => array('always_run', 'trim', 'alpha', 'min_length' => 1, 'max_length' => 1),
		),
		'last_name' => array(
            'label' => 'Last name',
            'rules' => array('always_run', 'trim', 'alpha_space', 'min_length' => 2, 'max_length' => 45),
		),
		'alias' => array(
            'label' => 'Alias',
            'rules' => array('always_run', 'trim', 'alpha_dash_dot', 'min_length' => 4, 'max_length' => 10),
		),
		'location' => array(
            'label' => 'Location',
            'rules' => array('always_run', 'trim', 'alpha_space', 'max_length' => 45),
		),
		'avatar' => array(
            'label' => 'Avatar',
            'rules' => array('always_run', 'trim', 'alpha_dash_dot', 'max_length' => 150),
		),
		'web' => array(
            'label' => 'Web',
            'rules' => array('always_run', 'trim', 'alpha_slash_dot', 'min_length' => 3, 'max_length' => 150),
		),
    );

    function get_user_profile($user) {
    	$u = new User();
    	$u->get_by_id($id);
    	
    	$p = $u->user_profile->get();
    	
    	if($p->exists()) return $p;
    	return NULL;
    }
}

/* End of file profile.php */
/* Location: ./application/models/profile.php */